package com.ppc.mapper.worker;

import com.github.pagehelper.Page;
import com.ppc.entity.Recording;
import com.ppc.entity.Tag;
import com.ppc.entity.UserPPC;
import com.ppc.entity.Worker;
import com.ppc.vo.WorkerCreditVO;
import com.ppc.vo.WorkerInfoQueryVO;
import com.ppc.vo.WorkerLoginVO;
import java.util.List;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

/**
 * 工人mapper
 *
 * @author Jeferry
 * @date 2023/12/20
 */
@Mapper
public interface WorkerMapper {

  /**
   * 根据手机号或邮箱查询工人
   *
   * @param user UserPPC实体类
   * @return {@link WorkerLoginVO}
   */
  WorkerLoginVO getWorkerByphoneOrEmail(UserPPC user);

  /**
   * 查询工人的信用信息
   *
   * @param workerid 工人的id
   * @return {@link List}<{@link WorkerCreditVO}>
   */
  List<WorkerCreditVO> checkCreditById(Integer workerid);

  /**
   * 查询工人的个人信息
   *
   * @param workerid 工人的id
   * @return {@link WorkerInfoQueryVO}
   */
  WorkerInfoQueryVO queryInformationById(Integer workerid);

  /**
   * 修改个人信息
   *
   * @param userPPC UserPPC实体类
   */
  void changeInformationInppc(UserPPC userPPC);

  /**
   * 查询工人的头像id
   *
   * @param userId 工人的id
   * @return {@link Integer}
   */
  @Select("select file_id from userppc where user_id=#{userId}")
  Integer queryFileID(Long userId);

  /**
   * 修改头像
   *
   * @param fileId  头像id
   * @param fileUrl 头像路径
   */
  void changeInformationInfile(Integer fileId, String fileUrl);

  /**
   * 修改工人标签
   *
   * @param currentId 工人id
   * @param tags      标签
   */
  @Update("update worker set worker_tag=#{tags} where user_id=#{currentId}")
  void changeWorkerTag(Long currentId, String tags);

  /**
   * 查询工人的标签
   *
   * @param workerId 工人的id
   * @return {@link String}
   */
  @Select("select worker_tag from worker where worker_id=#{workerId}")
  String queryTagsById(Long workerId);

  /**
   * 根据手机号或邮箱查询密码
   *
   * @param user UserPPC实体类
   * @return {@link String}
   */
  String getPasswordByphoneOrEmail(UserPPC user);

  /**
   * 查询标签名称
   *
   * @param tagId 标签id
   * @return {@link String}
   */
  @Select("select tag_name from tag where tag_id=#{tagId}")
  String queryTagName(Integer tagId);

  /**
   * 查询工人的SK1
   *
   * @param workerId 工人id
   * @return {@link String}
   */
  @Select("select d from sk where i=#{workerId}")
  String querySkOne(Integer workerId);

  /**
   * 查询工人的SK2
   *
   * @param workerId 工人id
   * @return {@link String}
   */
  @Select("select e from sk where i=#{workerId}")
  String querySkTwo(Integer workerId);

  /**
   * 查询当前工人的id
   *
   * @param userId 用户id
   * @return {@link Long}
   */
  @Select("select worker_id from worker where user_id=#{userId};")
  Long getCurrentWorkerId(Long userId);


  /**
   * 展示工人标签
   *
   * @param workerTags 标签数组
   * @return {@link Page}<{@link Tag}>
   */
  Page<Tag> selectTags(List<Integer> workerTags);

  /**
   * 查询标签
   *
   * @return {@link Page}<{@link Tag}>
   */
  @Select("select * from tag")
  Page<Tag> TagsQuery();

  /**
   * 查询信誉记录
   *
   * @return {@link List}<{@link String}>
   */
  @Select("select recording_content from recording where recording_type=1 and user_id=#{userId}")
  List<String> selectRecordingCredit(Long userId);

  /**
   * 查询金钱记录
   *
   * @return {@link List}<{@link String}>
   */
  @Select("select recording_content from recording where recording_type=0 and user_id=#{userId}")
  List<String> selectRecordingMoney(Long userId);

  /**
   * 注销账户
   *
   * @param currentWorkerId 工人的id
   */
  @Update("update worker set worker_status=2 where worker_id=#{currentWorkerId}")
  void logOffAccount(Long currentWorkerId);

  /**
   * 提现
   *
   * @param currentWorkerId 工人的id
   * @param workerCount     工人余额
   */
  @Update("update worker set worker_count=#{workerCount} where worker_id=#{currentWorkerId}")
  void cashWithdrawal(Long currentWorkerId, float workerCount);

  /**
   * 插入信誉记录
   *
   * @param recording Recording实体类
   */
  void insertIntoRecording(Recording recording);

  @Update("update userppc set file_id=#{fileId} where user_id=#{userId}")
  void updateImg(Long fileId, Long userId);

  void insertWorker(Worker worker);
  @Select("select worker_credit from worker where user_id=#{currentId}")
  Integer getWorkerCredit(Long currentId);
  @Select("select count(worker_id) from task where worker_id=#{currentWorkerId} and task_status!=4")
  Integer selectWorkerCount(Long currentWorkerId);
}
